<template>
      <div id="appversionwrap">
        <div class="appversionNew">
          <label class="inputfilwrap" for="appfile">
            <span class="iconadd">+</span>
            <p class="textdes">点击或拖拽上传apk文件</p>
            <input type="file" hidden="" name="appfile" id="appfile" ref="appfile">
          </label>
          <div class="appversionInfo">
           <form action="" id="uploadappfile" method="post" enctype="multipart/form-data">
              <div class="appitem">
                <span class="label">文件大小</span>
                <span class="name">Unknown</span>
              </div>
              <div class="appitem">
                <span class="label">发送时间</span>
                <div class="linewrap">
                  <input type="text" class="inputtime">
                </div>
              </div>
               <div class="appitem">
                <span class="label">强制更新</span>
                <div class="linewrap">
                  <label>
                    <input type="radio">
                    <span>是</span>
                  </label>
                  <label>
                    <input type="radio">
                    <span>否</span>
                  </label>
                </div>
              </div>
               <div class="appitem">
                <span class="label">更新日志</span>
                <div class="linewrap relative">
                  <textarea name="" id="" cols="30" rows="10" class="textarea"></textarea>
                  <span class="inputnum"><em>0</em>/500</span>
                </div>
              </div>
               <div class="appitem">
                <span class="label">公布范围</span>
                <div class="linewrap">
                  <label>
                    <input type="radio">
                    <span>所有用户</span>
                  </label>
                  <label>
                    <input type="radio">
                    <span>指定用户</span>
                  </label>
                </div>
                <div class="appitem">
                <span class="label"></span>
                <div class="linewrap">
                  <input type="text" class="inputtime" placeholder="请输入黄金先生账户，多个账户请用逗号隔开。">
                </div>
                </div>
              </div>
              <div class="postwrap">
                <button class="submit" @click="submit">提交</button>
              </div>
            </form>
          </div>
        </div>
      </div>
</template>
<script>
  import axios from 'axios'
  export default{
    name: 'appversionList',
    data () {
      return {
        total: 0,
        tableData: [],
        file: ''
      }
    },
    beforeCreate () {
      this.$store.commit('CHANGESTATE', [0, 1, 0, 0, 0, 0])
    },
    created () {
      // this.axios(1)
    },
    methods: {
      axios (index) {
        axios({
          headers: {'Content-Type': 'application/x-www-form-urlencoded'},
          url: this.$store.state.baseURI + 'oss/app/add',
          method: 'get',
          params: {
            page_num: index,
            token: this.$store.state.token
          }
        }).then(obj => {
          console.log(obj)
          if (obj.data.code === 100) {
            this.total = obj.data.data.total
            this.tableData = obj.data.data.list
          } else {
            // this.$router.push('/')
          }
        })
      },
      readfile (e) {
        var that = this
        var fileDom = this.$refs.appfile
        console.log(fileDom.files[0].size)
        if (window.FileReader) {
          var reader = new FileReader()
        } else {
          return false
        }
        reader.onload = function (event) {
          that.file = event.target.result
        }
        reader.readAsBinaryString(fileDom.files[0])
      },
      submit () {
        if (this.$refs.appfile.value === '') {
          alert('请上传文件')
          return false
        }
        // var that = this
        console.log(document.getElementById('appfile').files[0])
        document.getElementById('uploadappfile').attributes('action', this.$store.state.baseURI + 'oss/app/add')
        document.getElementById('uploadappfile').submit()
        /* axios({
          headers: {
            'Content-Type': 'application/x-www-form-urlencoded',
            'token': that.$store.state.token
          },
          url: this.$store.state.baseURI + 'oss/app/add',
          method: 'post',
          params: {
            file: document.getElementById('appfile').files[0],
            is_force: 1,
            publish_log: 'asdf',
            publish_time: '2017-07-18 00:00:00',
            scope: '0'
          }
        }).then(obj => {
          console.log(obj)
          if (obj.data.code === 100) {
            this.total = obj.data.data.total
            this.tableData = obj.data.data.list
          } else {
          }
        }) */
      }
    }
  }
</script>
<style lang="scss" rel="stylesheet/scss">
  .appversionNew{
    background: #fff;
    border-radius: 3px;
    margin-top: 20px;
    overflow: hidden;
    .inputfilwrap{
      display:block;
      height:116px;
      max-width: 640px;
      margin: 0 auto;
      border:2px dashed #C8C8C8;
      border-radius: 3px;
      margin-top: 40px;
      cursor: pointer;
      .iconadd{
        font-size: 48px;
        color: #ccc;
        margin: 20px;
        line-height: 80px;
      }
      .textdes{
        margin-top: -10px;
      }
    }
    .appversionInfo{
      max-width: 640px;
      margin: 10px auto;
      .appitem{
        margin: 15px 0;
        line-height: 40px;
        text-align: left;
        overflow: hidden;
        .label{
          float: left;
          width: 80px;
          text-align: left;
        }
        .linewrap{
          display: block;
          margin-left: 80px;
        }
        .inputtime{
          width: 100%;
          border:1px solid #e8e8e8;
          outline: 0;
          background: #f6f6f6;
          height: 38px;
          line-height: 38px;
          border-radius: 3px;
          box-sizing: border-box;
          text-indent: 8px; 
        }
        .textarea{
          width: 100%;
          height: 120px;
          border:1px solid #e8e8e8;
          border-radius: 3px;
          padding: 8px;
          box-sizing: border-box;
        }
        .inputnum{
          position: absolute;
          right: 8px;
          bottom: 8px;
          em{
            font-style: normal;
          }
        }
      }
    }
  }
</style>
